package com.u2ds;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.validation.Validator;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


/**
 * 设置在本机测试时的webmvc静态资源查找目录
 * 
 * @author ethan.yuan
 */
@Configuration
@Profile("local")
class WebMvcConfig extends WebMvcConfigurerAdapter {
	@Value("${spring.webmvc.assetsPath}")
	private String assetsPath;
	@Autowired
	private MessageSource messageSource;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		if (!this.assetsPath.isEmpty()) {
			registry.setOrder(Integer.MAX_VALUE - 2).addResourceHandler("/assets/**")
					.addResourceLocations("file:" + System.getProperty("user.dir") + this.assetsPath).setCachePeriod(0);
		}
	}
	
	@Override
	public Validator getValidator() {
//		LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean();
//		factory.setProviderClass(HibernateValidator.class);
//		factory.setValidationMessageSource(this.messageSource);
//		return factory;
		return null;
	}
}
